#ifndef __HEADER_TALK
#define __HEADER_TALK

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <netdb.h>
#include <stddef.h>

#include "config.h"

#define MYPORT 5050

/*
All messages that are to be used by the functions defined in here for sending and receiving MUST have a variable type of the type int as the first element.
This element tells the actual type of the message. Message definitions are present in config.h . Add to the list any new message types you want to.
*/

//Node of the queue used by server for sending
struct node_s
{
  int type;
  char *m;
  int size_m;
  struct sockaddr_in dest_add;
  struct node_s* next;
};
typedef struct node_s sn_s;

//Node of the queue used by server for receiving
struct node_r
{
  int type;
  char *msw;
  int size_m;
  struct sockaddr_in source_addr;
  struct node_r* next;
};
typedef struct node_r sn_r;

sn_s *sendQ;
sn_r *recvQ;

void *fnsend();		//Function which puts messages in send queue onto the network.
void *fnrecv();		//Function which puts messages on network into receive queue.
void *main_sendrecv(void *node_no);	//Call this from a programme outside to make your machine to start talking to others. Argument to be passed is the nodeno in char* format
void queue_init();	//Initializes the queues to NULL.
//Function to put message msg of size size_msg into the send_queue.
void queue_send(void *msg, size_t size_msg, struct sockaddr_in dest_addr);
//Function to receive message of type typ from receive_queue into mw. 
int queue_recv(char *mw, int typ, int *size_msg, struct sockaddr_in *source_addr);

#endif //__HEADER_TALK
